﻿using System;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private string _filePath1, _filePath2;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _filePath1 = openFileDialog1.FileName;
                textFile1.Text = _filePath1;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _filePath2 = openFileDialog1.FileName;
                textFile2.Text = _filePath2;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(string.IsNullOrEmpty(_filePath1) || string.IsNullOrEmpty(_filePath2))
            {
                MessageBox.Show("请先选择两个文件","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            try
            {
                string content1 = File.ReadAllText(_filePath1);
                string content2 = File.ReadAllText(_filePath2);
                string dataDir = Path.Combine(Application.StartupPath, "data");
                Directory.CreateDirectory(dataDir);

                string mergedFilePath = Path.Combine(dataDir, "merged_result.txt");

                File.WriteAllText(mergedFilePath, content1 + content2);
                MessageBox.Show($"文件已合并到:\n{mergedFilePath}", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"合并失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }


    }
}
